var net = require('net');
var HOST = '127.0.0.1';
var PORT = 9999;
net.createServer(function(sock){

	console.log('CONNECTED: ' + sock.remoteAddress + ':' + sock.remotePort);
	sock.write('服务器连接成功');
	
	sock.on('data', function(data){
	
		console.log('DATA ' + sock.remoteAddress + ': ' + data);  
        	// 回发该数据，客户端将收到来自服务端的数据  
        	sock.write('You said "' + data + '"');  
	});

	sock.on('close', function(data){
	
		console.log('CLOSED: ' + sock.remoteAddress + ' ' + sock.remotePort);
	});

}).listen(PORT,HOST);

console.log('Server listening on ' + HOST +':'+ PORT);
